import {
    request
} from "../../request/request.js";
var util = require('../../utils/util.js')
var dayTime = util.formatTime(new Date());
var weektime = util.weekId(new Date());

// console.log(dayTime);
Page({
    data: {
        HI: dayTime,
        // 星期
        Week: weektime,
        thisWeek: "",
        username: "",
        // weekdayList: "",
        // 课表
        CoursesList: [],
        scrollTop: 0,
        Publisher: [{
                id: 0,
                PublisherTeam: "T-dog",
                date: "8:00",
                information: "踢球"
            },
            {
                id: 1,
                PublisherTeam: "Symeet",
                date: "18:00",
                information: "开会"
            },
            {
                id: 2,
                PublisherTeam: "团学",
                date: "20:00",
                information: "颁奖"
            },
            {
                id: 3,
                PublisherTeam: "19网络工程三班",
                date: "20:00",
                information: "开会"
            },
            {
                id: 4,
                PublisherTeam: "19网络工程三班",
                date: "20:00",
                information: "开会"
            },
            {
                id: 5,
                PublisherTeam: "19网络工程三班",
                date: "20:00",
                information: "开会"
            },
        ]
    },
    onLoad: function (options) {
        var that = this;
        let baseUrl = 'http://172.17.60.141:80/';
        let userId = wx.getStorageSync("userId");
        request({
                url: baseUrl + 'getCourses',
                data: {
                    user: userId,
                },
                method: 'GET',
            })
            .then(result => {
                console.log(that.data.Week)
                for (let i = 0; i < result.data.CoursesList.length; i++) {
                    if (that.data.Week == result.data.CoursesList[i].week && result.data.CoursesList[i].class_week.indexOf(result.data.This_Week) >= 0) {
                        console.log(result.data.CoursesList[i])
                        var newArray = result.data.CoursesList[i]
                        that.data.CoursesList = that.data.CoursesList.concat(newArray);
                        that.setData({
                            CoursesList: that.data.CoursesList,
                        })
                    }
                }
                this.setData({
                    username: result.data.Student_Name,
                    thisWeek: result.data.This_Week
                })
                wx.setStorageSync('username', result.data.Student_Name);
                wx.setStorageSync('timeTable', result.data.CoursesList)
            })
    },

    // 置顶与删除
    // ListTouch触摸开始
    ListTouchStart(e) {
        this.setData({
            ListTouchStart: e.touches[0].pageX
        })
    },
    ToTimeTable(e) {
        wx.navigateTo({
            url: '/pages/ClassTable/index',
        })
    },
    // ListTouch计算方向
    ListTouchMove(e) {
        this.setData({
            ListTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > 0 ? 'right' : 'left'
        })
    },

    // ListTouch计算滚动
    ListTouchEnd(e) {
        if (this.data.ListTouchDirection == 'left') {
            this.setData({
                modalName: e.currentTarget.dataset.target
            })
        } else {
            this.setData({
                modalName: null
            })
        }
        this.setData({
            ListTouchDirection: null
        })
    },
    toClaaTable:function (e) {
        wx.navigateTo({
            url: '/pages/ClassTable/index',
        })
    }
})